define(function(require, exports, module) {
	var $ = require('$');
	var formcc = require('form');
	var nav = require("bootstrap_nav");
	var bootbox = require("bootbox");
	var store = require("store");
	var loader = require("./loader/loader");
	require("bootstrap-datetimepicker.min.css");
	// require("bootstrap_datetimepicker.zh-CN");
	require("bootstrap_datetimepicker");
	require('select2.css');
	require('select2');

	exports.init = function(divId, data) {
		var dictionary = {};
		if (data)
			dictionary = data;
		new formcc({
			attrs : {
				title : "更新字典数据",
				spansize : 'span12',
				id : "dictionaryreturnform",
				items : [{
          isText : true,
          label : "类型",
          id : 'type',
          name : 'type',
          type : "text",
          style : "width:50%",
          value : dictionary.type
        },{
          isText : true,
          label : "主键",
          id : 'data_key',
          name : 'data_key',
          type : "text",
          style : "width:50%",
          readonly : false,
          value : dictionary.data_key
        },{
          isText : true,
          label : "键值",
          id : 'data_value',
          name : 'data_value',
          type : "text",
          style : "width:50%",
          readonly : false,
          value : dictionary.data_value
        },{
          isText : true,
          label : "备注",
          id : 'comments',
          name : 'comments',
          type : "text",
          style : "width:50%",
          value : dictionary.comments
        }],
				buttons : [ {
					text : "保存",
					id : "btn_save",
					type : "submit",
					style : "btn btn-contrast",
					icon : "save",
				}, {
					text : "取消",
					id : "btn_cancel",
					style : "btn",
					type : "button",
					icon : "undo",
				}]

			},
			renderTo : divId,
			afterRender : function() {		
				var theme = require('bootstrap_theme');
				theme.setValidateForm($("#dictionaryreturnform"), function() {
					var formdata = {
					    id : dictionary.id,
					    type : $("#type").val(),
					    url : $("#url").val(),
					    data_key : $("#data_key").val(),
					    data_value : $("#data_value").val(),
					    comments : $("#comments").val()
					};
					loader.loading("正在提交，请稍等……");
					$.ajax({
						url :"/dictionary/doEdit.do",
						dataType : "json",
						data : "data=" + JSON.stringify(formdata),
						type : "POST",
						async : false,
						success : function(json) {
							if(json.flag == '000000'){
	              nav.toPageView("admin/dictionary.html");
	              loader.noloading();                   
		          } else {
		            oauth2Relogin();                    
		          }
						},
						error : function() {
							loader.noloading();
							bootbox.alertTimeout("网络请求失败，请重试！");
						}
					});
				});

				$('#btn_cancel').on('click', function() {
					nav.toPageView("admin/dictionary.html");
				});
			}
		});
	};
});
